<?php

namespace App\Http\Controllers\Long;

use App\Http\Controllers\Controller;
use App\Services\Login;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class LoginController extends BaseController
{
    /**
     * 登录
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(Request $request){
        if($request->ajax() && $_POST){
            $account = Input::get('account');
            $pass = Input::get('pass');
            $login_res = Login::checkLogin($account , $pass , 'long');
            if($login_res){
                Login::setValue($login_res);//存储session
                $this->ajaxReturn('200' , Login::$errorMessage , array('url' => '/index/index'));
            }else{
                $this->ajaxReturn('300' , Login::$errorMessage);
            }
        }
        return view('login.index');
    }

    /**
     * 退出登录
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function logout(Request $request){
        $request->session()->flush();
        return redirect('/login/logout');
    }
}
